﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PedesTrainProject.GUI
{
    public partial class AdjustCars : Form
    {
        private SimulationCreator simulationCreator;
        private DateTime tempDate;
        
        private System.Windows.Vector position;
        public AdjustCars(SimulationCreator _simulationCreator, System.Windows.Vector _position)
        {
            InitializeComponent();
            simulationCreator = _simulationCreator;
            position = _position;

           
            tempDate = simulationCreator.CoreGUI.getStartTime();
            groupBox1.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
            tempDate =  tempDate.AddHours(3);
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox2.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                groupBox2.Enabled = false;
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                groupBox6.Enabled = false;
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            }
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox3.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                groupBox6.Enabled = false;
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            }
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox4.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                groupBox6.Enabled = false;
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            }
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox5.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                groupBox5.Enabled = false;
                groupBox6.Enabled = false;
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            }
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox6.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                groupBox6.Enabled = false;
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            }
            if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox7.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
            
                groupBox7.Enabled = false;
                groupBox8.Enabled = false;
                return;
            } if (tempDate < simulationCreator.CoreGUI.getEndTime())
            {
                groupBox8.Text = " " + (tempDate.Hour) + ":00 - " + (tempDate.Hour + 3) + ":00";
                tempDate = tempDate.AddHours(3);
            }
            else
            {
                
                groupBox8.Enabled = false;
                return;
            }
           
           
          
        }

        private void groupBox6_Enter(object sender, EventArgs e)
        {

        }

        private void AdjustCars_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            simulationCreator.Enabled = true;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<int> inter = new List<int>();

            inter.Add(Convert.ToInt32(numericUpDown1.Value));
            inter.Add(Convert.ToInt32(numericUpDown2.Value));
            inter.Add(Convert.ToInt32(numericUpDown3.Value));
            inter.Add(Convert.ToInt32(numericUpDown4.Value));
            inter.Add(Convert.ToInt32(numericUpDown5.Value));
            inter.Add(Convert.ToInt32(numericUpDown6.Value));
            inter.Add(Convert.ToInt32(numericUpDown7.Value));
            inter.Add(Convert.ToInt32(numericUpDown8.Value));

            List<DateTime> dates = new List<DateTime>();

            dates.Add(simulationCreator.CoreGUI.getStartTime());
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(3));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(6));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(9));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(12));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(15));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(18));
            dates.Add(simulationCreator.CoreGUI.getStartTime().AddHours(21));

            List<KeyValuePair<DateTime, int>> intervals = new List<KeyValuePair<DateTime, int>>();

            for (int i = 0; i < 6; i++)
            {
                intervals.Add(new KeyValuePair<DateTime, int>(dates[i], inter[i]));
            }
            if (simulationCreator.CoreGUI.inFlowFlagPresent(position) == false)
            {
                simulationCreator.CoreGUI.addInFlowFlag(intervals, position);
            }
            else
                simulationCreator.CoreGUI.setInFlowFlag(intervals, position);

            simulationCreator.Enabled = true;
            this.Close();
        }

        private void AdjustCars_FormClosed(object sender, FormClosedEventArgs e)
        {
            simulationCreator.Enabled = true;
        }
    }
}
